#!/bin/bash
clear
rm a.out

LIBC=/home/atreyu/tmp/newlib-1.18.0/arm-linux-gnueabi/newlib/libc.a
LIBM=/home/atreyu/tmp/newlib-1.18.0/arm-linux-gnueabi/newlib/libm.a

echo "Compiling..."
arm-none-eabi-gcc lab3.c startup_gcc.c linkedqueue.c uart.c fifo.c -g -mthumb -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=softfp -Os -ffunction-sections -fdata-sections -MD -std=c99 -Wall -pedantic -DPART_LM4F120H5QR -c -I/home/atreyu/Source/stellaris/stellarisware -DTARGET_IS_BLIZZARD_RA1 -L/home/atreyu/Source/stellaris/stellarisware/driverlib/gcc-cm4f/ -ldriver-cm4f

echo "Linking..."
arm-none-eabi-ld -T linker.ld --entry ResetISR -o a.out startup_gcc.o lab3.o linkedqueue.o uart.o fifo.o --gc-sections

#arm-none-eabi-ld -T linker.ld --entry ResetISR --gc-sections -L/usr/arm-none-eabi/lib -o a.out startup_gcc.o lab3.o linkedqueue.o uart.o fifo.o LIBC LIBM

#arm-none-eabi-gcc -Wl,--script=linker.ld -Wl,--entry=ResetISR -Wl,--gc-sections -L/usr/arm-none-gnueabi/lib/ -o a.out -lgcc -lc -lm -lrdimon lab3.o startup_gcc.o linkedqueue.o uart.o fifo.o libm.a libc.a libgcc.a 

#arm-none-eabi-gcc --specs=rdimon.specs -lgcc -lc -lm -lrdimon -o a.out lab3.c startup_gcc.c linkedqueue.c uart.c fifo.c -g -mthumb -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=softfp -Os -ffunction-sections -fdata-sections -MD -std=c99 -Wall -pedantic -DPART_LM4F120H5QR -I/home/atreyu/Source/stellaris/stellarisware -DTARGET_IS_BLIZZARD_RA1

echo "Copying object files..."
arm-none-eabi-objcopy -O binary a.out lab3.bin

echo "Flashing to rom..."
#lm4flash timerled.bin
sudo ~/Source/stellaris/lm4tools/lm4flash/lm4flash lab3.bin

echo "Build terminated."

#ta info: yuanye@uvic.ca

#sudo minicom -D /dev/rfcomm0 configuration stellarisbt
